<%-- 
    Document   : addTicket
    Created on : Mar 19, 2013, 9:20:08 AM
    Author     : mudassar
--%>

<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@include file="../common/script.jsp" %>
<!DOCTYPE html>
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
        <%@include file="../common/title.jsp" %>

        <script type="text/javascript">
            $(function() {
                $( "#hospitalId" ).autocomplete({
                    source: "../ajaxCallForHospitalList.htm",
                    minLength: 1    
                });
            });
        </script>

        <script type="text/javascript">
            $(function() {
                $( "#appSpecialistId" ).autocomplete({
                    source: "../ajaxCallForAppSpecialist.htm",
                    minLength: 1    
                });
            });
        </script>
        <script type="text/javascript">
            $(function() {
                $( "#followupDate").datetimepicker({dateFormat: 'yy-mm-dd',stepMinute:15, hourMin:7,hourMax:22,minDate:0});
            });
        </script>
        <script type="text/javascript">
            var rules=new Array();
            
            rules[0]='notes|required|please enter notes';
            rules[1]='callType.callTypeId|required|please Select CallType';
            rules[2]='disposition.dispositionId|required|please Select Disposition';
            rules[3]='followupDate|custom|followupDate1()';
            rules[4]='ticketDesc|required|please enter ticket desc';
            rules[5]='recordingId|required|please enter call recording id';
            rules[6]='doctor.doctorId|custom|selectDoctor()';
            rules[7]='cheifComplaint|custom|enterChiefComplaint()';
            
            function selectDoctor(){
                    //alert('inside selectDoctor');
                    var e1 = document.getElementById("callType.callTypeId");
                    var selectedCallType = e1.options[e1.selectedIndex].value;
                    var e2 = document.getElementById("dispositionId");
                    var selectedDisposition = e2.options[e2.selectedIndex].value;
                    if((selectedCallType==6 || selectedCallType==7) && (selectedDisposition==8 || selectedDisposition == 13 || selectedDisposition == 26)){
                        //alert('selectedCallType :'+selectedCallType);
                        var doctorName = document.getElementById("doctor.doctorId").value;
                       // alert('doctorName :'+doctorName);
                        if(doctorName==0){
                            return 'please select doctor name';
                        }
                    }
                }
                function enterChiefComplaint(){
                    //alert('inside enterChiefComplaint');
                    var e1 = document.getElementById("callType.callTypeId");
                    var selectedCallType = e1.options[e1.selectedIndex].value;
                    var e2 = document.getElementById("dispositionId");
                    var selectedDisposition = e2.options[e2.selectedIndex].value;
                    if((selectedCallType==6 || selectedCallType==7) && selectedDisposition ==8){
                        //alert('selectedCallType :'+selectedCallType);
                        var cheifComplaint = document.getElementById("cheifComplaint").value;
                        //alert('cheifComplaint :'+cheifComplaint);
                         if(cheifComplaint==""){
                            return 'please select cheifComplaint';
                        }
                    }
                }
                
                
            //FOR DISPOSITION LIST
            function showDispositionList(){
                var callTypeId=document.getElementById("callType.callTypeId").value;
                //alert("insideshowDispositionList value of callTypeId :"+callTypeId);
                $.ajax({
                    data: ({'callTypeId1' : callTypeId}),
                    url: "../ajaxCallForDispositionList.htm",
                    dataType: "json",
                    success:function(json){
                        //alert('inside success event');
                        var i=0;
                        document.getElementById("dispositionId").length=0;
                        
                        var anOption1=document.createElement("OPTION");
                        document.form1.dispositionId.options.add(anOption1);
                        anOption1.text="-";
                        anOption1.value="";
                        for(i=0;i<json.length;i++){
                            //alert('inside if ');
                            var anOption=document.createElement("OPTION");
                            document.form1.dispositionId.options.add(anOption);
                            //alert('anOption.text: '+anOption.text);
                            anOption.text=json[i].label;
                            anOption.value=json[i].value;
                        }
                    },
                    error: function(e){
                        
                        alert("Error:  method not called ");
                    }
                });
            }
            //End
            
            function followupDate1(){
                var flag=0;
                var e = document.getElementById("dispositionId");
                var selectedDisposition = e.options[e.selectedIndex].value;
                //alert("selectedDisposition"+selectedDisposition);
            <c:forEach items="${dispositionList}" var="dispositionItem">
                    
                    if(selectedDisposition==${dispositionItem.dispositionId}
                        && ${dispositionItem.followupRequired=='true' }){
                        var flDate = document.getElementById("followupDate").value;
                        if(flDate==""){
                            //alert("flag=1");
                            flag=1;
                        }
                    }
            </c:forEach>
                    //alert("outside of c for each"+flag);
                    if(flag==1){
                        return 'followupDate required';
                    }else{
                        
                        return null;
                    }
                } //END
                
                
                
        </script>
    </head>
    <body onLoad="yav.init('form1',rules,'inline');">

        <div class="in_02">
            <%@include file="../common/message.jsp" %>
            <form:form id="form1" name="form1"  modelAttribute="ticket" method="POST" action="addTicket.htm" cssClass="userInputForm" >
                <fieldset>
                    <legend>Add Ticket</legend>
                    <table class="formTable1">
                        ${customer.customerId}
                        <form:hidden path="customer.customerId"/>

                        <tr>
                            <td><spring:message code="notes"/>:<br/> 
                                <form:textarea path="notes" id="notes" cssClass="userInputLarge"/><br/>
                                <span id="errorsDiv_notes"></span>
                            </td>
                            <td><spring:message code="cheifComplaint"/>:<br/> 
                                <form:textarea path="cheifComplaint" cssClass="userInputLarge"/><br/>
                                <span id="errorsDiv_cheifComplaint"></span>
                            </td>
                        </tr>
                        <tr>
                            <td><spring:message code="callType"/>:<br/>
                                <form:select  path="callType.callTypeId"  cssClass="userInputLarge" onchange="showDispositionList();">
                                    <form:option value="" label="-"></form:option>
                                    <form:options items="${callTypeList}" itemLabel="callTypeName" itemValue="callTypeId"></form:options>
                                </form:select><br/>
                                <span id="errorsDiv_callType.callTypeId"></span><br/>
                            </td>
                            <td><spring:message code="disposition"/>:<br/>
                                <form:select  path="disposition.dispositionId"  id="dispositionId" cssClass="userInputLarge" >
                                    <form:option value="" label="-"></form:option>
                                    <form:options items="${dispositisdasdsonList}" itemLabel="dispositionName" itemValue="dispositionId"></form:options>
                                </form:select>
                                <span id="errorsDiv_disposition.dispositionId"></span><br/>
                            </td>
                        </tr>
                        <tr>
                            <td><spring:message code="doctorName"/>:<br/>
                                <form:select  path="doctor.doctorId" cssClass="userInputLarge">
                                    <form:option value="0" label="-"></form:option>
                                    <form:options items="${doctorList}" itemLabel="doctorName" itemValue="doctorId"></form:options>
                                </form:select><br/>
                                <span id="errorsDiv_doctor.doctorId"></span><br/>
                            </td> 
                            <td>Ticket Description<br/> 
                                <form:textarea path="ticketDesc" cssClass="userInputLarge"/><br/>
                                <span id="errorsDiv_ticketDesc"></span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <p><label>Hospital Name:</label><br />
                                    <input type="text" name="hospitalId" id="hospitalId"  class="userInputLarge" onchange="test();" />
                            </td>
                            <td>
                                <p><label>Exclusive Specialist Name:</label><br />
                                    <input type="text" name="appSpecialistId" id="appSpecialistId"  class="userInputLarge"  />
                            </td>
                        </tr>
                        <tr>
                            <td><spring:message code="status"/>:<br/>
                                <form:select  path="status"  cssClass="userInputMedium">
                                    <form:option value="Open" label="-">Open</form:option>
                                    <form:option value="Closed" label="-">Closed</form:option>
                                </form:select><br/>
                            </td>
                            <td><spring:message code="followupDate"/>:<br/>
                                <input id="followupDate" name="followupDate1"  class="userInputLarge"/>
                                <span id="errorsDiv_followupDate"></span><br/>
                            </td>
                        </tr>
                        <tr>
                            <td><spring:message code="assignedTo"/>:<br/>
                                <form:select  path="assignedTo.userId"  cssClass="userInputLarge">
                                    <form:option value="0" label="-"></form:option>
                                    <form:options items="${activeUserList}" itemLabel="username" itemValue="userId"></form:options>
                                </form:select><br/>
                            </td>
                            <td><spring:message code="callRecordingID"/>:<br/> 
                                <input  name="recordingId" id="recordingId" class="userInputLarge"/><br/>
                                <span id="errorsDiv_recordingId"></span>
                            </td>
                        </tr>
                        <tr>
                            <td>
                                <input type="submit" name="submit" id="submit" style="width:100px;float: left; margin: 0 20px 0 0;" value="<spring:message code="button.Create"/>" onclick="return yav.performCheck('form1', rules, 'inline');" />
                            </td>
                            <td>
                                <input type="button" style="width:100px;" value="Close Window" onclick="window.close();window.opener.location.reloadPage(true);"/>
                            </td>
                        </tr>
                    </table>
                </fieldset>
            </form:form>
        </div>

    </body>
</html>
